import { HttpRequest, Md5 } from 'xo-web-base';
import { User } from '@/models/user';
/**
 * 用户接口
 */
export default class UserService {
  /**
   * 用户登录
   * @param account
   * @param pwd
   * @returns
   */
  static login(account: string, pwd: string) {
    return HttpRequest.post<User>('/admin/login', {
      account: account,
      pwd: Md5.encode(pwd),
    });
  }
  /**
   * 免密登录
   * @param mobile
   * @param code
   * @returns
   */
  static freeLogin(mobile: string, code: string) {
    return HttpRequest.post<User>('/admin/login', {
      mobile: mobile,
      code: code,
      type: 1,
    });
  }

  /**
   * 注册
   * @param code 短信验证码
   * @param mobile
   * @param pwd
   * @returns
   */
  static register(account: string, pwd: string) {
    return HttpRequest.post<User>('/admin/galleryUser/save', {
      account: account,
      password: Md5.encode(pwd),
      sendType: 1,
    });
  }
  /**
   * 退出登录
   * @returns
   */
  static logout() {
    return HttpRequest.post<User>('/admin/user/logout', {});
  }
  /**
   * 忘记密码
   * @param code 短信验证码
   * @param mobile
   * @param pwd
   * @returns
   */
  // static forgetPwd(code: string, mobile: string, pwd: string) {
  //   return HttpRequest.post<User>('/web/user/updatePwdByMobile', {
  //     code: code,
  //     mobile: mobile,
  //     pwd: Md5.encode(pwd),
  //     sendType: 2,
  //   });
  // }
  static getUserInfo() {
    return HttpRequest.post<User>('/web/user/info', {});
  }
}
